<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="/FInclude/includeTaglibs.jsp"%>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<link rel="stylesheet" href="${frontPath}/style/ckeditor.plugin.css" />
<c:import url="/FInclude/backEndCssJs.jsp" />
<script type="text/javascript"
	src="${frontPath}/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="${frontPath}/js/ckeditor.plugin.js"></script>
<script src="${frontPath}/js/DatePicker/WdatePicker.js"></script>
</head>
<body>
<div><c:if test="${type.isParent eq 1}"><button add>新增</button></c:if><button mod>修改</button><button del="${type.typeId }">删除</button></div>
	<form action="add.json" method="post" onsubmit="return false;" add  style="display:none">
	<div class="container-fluid">
		<div class="panel panel-default">
			<div class="row">
				<div class="input-group">
					<button class="form-control" onclick="history.back();">返回</button>
				</div>
				<div class="input-group">
					<span class="input-group-addon">名称</span>
					<input style="width:120px" name="name">
				</div>
				<div class="input-group">
					<span class="input-group-addon">英文名称</span>
					<input style="width:120px" name="e_name">
				</div>
				<div class="input-group">
					<span class="input-group-addon">是否部门</span>
					<select name="isParent">
						<option value="1">是</option>
						<option value="0">否</option>
					</select>
				</div>
				<div class="input-group">
					<span class="input-group-addon">图片</span>
					<img src="">
					<input type="file" style="width:80px" name="upload">
					<input name="pic" type="hidden" >
					<input type="hidden" name="parentId" value="${type.typeId }">
				</div>
				<div class="input-group">
					<span class="input-group-addon">详情</span>
					<textarea style="width:320px" name="detail"></textarea>
				</div>
				<div class="input-group">
					<span class="input-group-addon">英文详情</span>
					<textarea style="width:320px" name="e_detail"></textarea>
				</div>
				<div class="input-group">
					<input type="submit" class="form-control" a>
				</div>
			</div>
		</div>
	</div>
	</form>
	
	<form action="mod.json" method="post" onsubmit="return false;" mod style="display:none">
	<div class="container-fluid">
		<div class="panel panel-default">
			<div class="row">
				<div class="input-group">
					<button class="form-control" onclick="history.back();">返回</button>
				</div>
				<div class="input-group">
					<span class="input-group-addon">名称</span>
					<input style="width:120px" name="name" value="${type.name }">
				</div>
				<div class="input-group">
					<span class="input-group-addon">英文名称</span>
					<input style="width:120px" name="e_name" value="${type.e_name }">
				</div>
				<div class="input-group">
					<span class="input-group-addon">是否部门</span>
					<select name="isParent">
						<option value="1" <c:if test="${type.isParent eq 1 }">selected</c:if>>是</option>
						<option value="0" <c:if test="${type.isParent eq 0 }">selected</c:if>>否</option>
					</select>
				</div>
				<div class="input-group">
					<span class="input-group-addon">图片</span>
					<img src="${frontPath }${type.pic }">
					<input type="file" style="width:80px" name="upload">
					<input name="pic" type="hidden" value="${type.pic }">
					<input type="hidden" name="typeId" value="${type.typeId }">
				</div>
				<div class="input-group">
					<span class="input-group-addon">详情</span>
					<textarea style="width:320px" name="detail">${type.detail }</textarea>
				</div>
				<div class="input-group">
					<span class="input-group-addon">英文详情</span>
					<textarea style="width:320px" name="e_detail">${type.e_detail }</textarea>
				</div>
				<div class="input-group">
					<input type="submit" class="form-control" a>
				</div>
			</div>
		</div>
	</div>
	</form>
	<script>
	$("input[type=file]").change(function(){
		var _this = $(this);
		$(this).uploadFile("../../file/image.json",{},function(data){
			_this.prev().attr("src", $.frontPath + data.url);
			_this.next().val(data.url);
		});
	});
	
	$("button[add]").click(function(){
		$("form[mod]").hide();
		$("form[add]").show();
	});
	
	$("button[mod]").click(function(){
		$("form[add]").hide();
		$("form[mod]").show();
	});
	
	$("form[add] [type=submit]").click(function(){
		var _this = $("form[add]");
		_this.postData(
				_this.attr("action"),
				{},
				function(data){
					$.box("添加成功",function(){
						var a = parent.$("#leftTree").zTree.getZTreeObj("leftTree");
						a.addNodes(a.getSelectedNodes()[0], {name:data.type.name,isParent:0,id:data.type.typeId,pId:0});
					});
		});
	});
	
	$("form[mod] [type=submit]").click(function(){
		var _this = $("form[mod]");
		_this.postData(
				_this.attr("action"),
				{},
				function(data){
					$.box("修改成功",function(){
						var tree = parent.$("#leftTree").zTree.getZTreeObj("leftTree");
						var node = tree.getSelectedNodes()[0];
						node.name = data.type.name;
						tree.updateNode(node);
					});
		});
	});
	$("button[del]").click(function(){
		$.box({title:"删除", message:"是否删除选中",ok:function(){
			var id = $(this).attr("del");
			$(this).postData(
					"del.json",
					{typeId:id},
					function(data){
					if(data.hasError){
						$.box(data.error_0);
						return;
					}
						$.box("删除成功",function(){
							var tree = parent.$("#leftTree").zTree.getZTreeObj("leftTree");
							var node = tree.getSelectedNodes()[0];
							tree.removeNode(node);
							parent.$("#centeriframe").attr("src", "");
						});
			});
		}});
	});
</script>
</body>
</html>